package com.huluobo.a2201mvvm_imdemo.mvvmdemo;

import androidx.lifecycle.MutableLiveData;

import com.huluobo.a2201mvvm_imdemo.mvpdemo.UserBean;

/**
 * Created by LC on 2024/3/21.
 * Repo用来替代Model 因为在MVVM模式中,有个VM层,名字相同,容易混淆
 * 所以用Repo来代替,本质上都是Model层,数据仓库
 * MutableLiveData LiveData的变种,Mutable可变的意思
 */
public class LoginRepo {
    public void login(String username, String password, MutableLiveData<UserBean> success,
                      MutableLiveData<String> failed) {
        if (username.equals("lcc") && password.equals("123")) {
            //成功的LiveData,给LiveData赋值
            success.setValue(new UserBean(username, password));
        } else {
            //失败的LiveData
            failed.setValue("用户名密码不匹配");
        }
    }
}
